package com.itheima.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @description: 阿里云手机短信服务
 * @author: wangjingliang
 * @create: 2019-11-20 18:46
 **/
public class QuerySendDetailsUtils {
    public static  String PageSize = "SMS_177549103";//发送短信验证码
    public static  String ORDER_NOTICE = "SMS_177544132";//体检预约成功通知
    // 云账号AccessKey有所有API访问权限，建议遵循阿里云安全最佳实践，创建并使用RAM子账号进行API访问或日常运维，请登录 https://ram.console.aliyun.com 创建。
    public  static  String accessKeyId = "LTAI4FicqshVWkTMq4yvYGK4";
    public  static String accessKeySecret = "6ZQjSD8jfeqFpmhk6k2LcQgUPgSc6D";
    public static  String SendDate = "传智健康";
    public static String RegionId= "cn-hangzhou";

    public static CommonResponse sendDetails(String PhoneNumber, String code) {
        DefaultProfile profile = DefaultProfile.getProfile(SendDate, accessKeyId, accessKeySecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", PhoneNumber);
        request.putQueryParameter("SignName", SendDate);
        request.putQueryParameter("TemplateCode", PageSize);
        request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            return response;
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }

        return null;
    }
    public static CommonResponse SendSms(String PhoneNumber, Object name, Object setmealname, Object orderDate, String templateCode) {
        DefaultProfile profile = DefaultProfile.getProfile(SendDate, accessKeyId, accessKeySecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", PhoneNumber);
        request.putQueryParameter("SignName", SendDate);
        request.putQueryParameter("TemplateCode", ORDER_NOTICE);
        request.putQueryParameter("TemplateParam", "{\"name\":\""+name+"\",\"setmealname\":\""+setmealname+"\",\"orderDate\":\""+orderDate+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
            return response;
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return null;
    }
}
